﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace OF.Web
{
    public partial class error : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //tip.Text = CreateOrderSN(); //Create(999);//GetOrderNumber();
            string photo = "iVBORw0KGgoAAAANSUhEUgAAALkAAAA1CAYAAAAd30r/AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyBpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBXaW5kb3dzIiB4bXBNTTpJbnN0YW5jZUlEPSJ4bXAuaWlkOkQ1QTM3RTM3MzdDNTExRTNBRkNEREM5OUY2NzMzOEY5IiB4bXBNTTpEb2N1bWVudElEPSJ4bXAuZGlkOkQ1QTM3RTM4MzdDNTExRTNBRkNEREM5OUY2NzMzOEY5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YE8WXcnflzHzXWpyfDTOxNFqq80aBR50GZq4VeFSOu6pBvl+EzBlXSpThnmRYJ/M0BFYoErRuNmon1+lwqWWrEALRxVgEffI2n7pJN8gIRbJJViUXGbRPSBbulPT0W7p/UpLrcW9Uf1sw4d4387/r/OI2PfrOvmszynkTffS/hd/I5ogHzy0hGgOfprkxlxSRPG4ulbA2xpisBx7NdpSFdGxhLZAduWxxWKBovads0g9+TpN07+P8by5EHuyZMHuSdPHuSePHmQe/LkQe7Jkwe5J08e5J6+Zfq/AAMAg/6Hy+isZkAAAAAASUVORK5CYII=";
            tip.Text = OF.Common.Utils.UploadPhoto("test.png","image/png", photo);  //图片64位编码字符串
        }

        public string CreateOrderSN()
        {
            string ordersn = DateTime.Now.ToString("yyMMddHHmmss") + Next(1000, 1).ToString();
            DAL.Orders dal_order = new DAL.Orders();
            //判断流水号是否存在
            var ds = dal_order.GetList(" ordersn='" + ordersn + "'");
            if (ds != null && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
            {
                return CreateOrderSN();
            }
            else
            {
                return ordersn;
            }
        }


        public string CreateOrderNumber()
        {
            string Number = DateTime.Now.ToString("yyMMddHHmmss");//yyyyMMddHHmmssms
            return Number + "_" + Next(1000, 1).ToString();
        }
        private static int Next(int numSeeds, int length)
        {
            byte[] buffer = new byte[length];
            System.Security.Cryptography.RNGCryptoServiceProvider Gen = new System.Security.Cryptography.RNGCryptoServiceProvider();
            Gen.GetBytes(buffer);
            uint randomResult = 0x0;//这里用uint作为生成的随机数  
            for (int i = 0; i < length; i++)
            {
                randomResult |= ((uint)buffer[i] << ((length - 1 - i) * 8));
            }
            return (int)(randomResult % numSeeds);
        }

        public string Create(int val)
        {
            // 根据id生成唯一订单号
            // sin函数在 0-∏/2 之间取值是唯一的，不过在 sin(1.4) 之后变化不明显
            // 所以取长度 9 的话，在 1400万 之后就要重新开始一个循环，用前缀作为区别
            // 这里是取的 9 位长度和 2 位前缀，可以保证14亿订单号不重复，如果不够，可延长到 10 位或者增加前缀的位数

            long pre = val / 14000000;       // 每1400万的前缀
            char[] tempcode = Convert.ToString(Math.Sin((val % 14000000 + 1) / 10000000.0) * 123456789).ToCharArray();    // 这里乘以 123456789 一是一看就知道是9位长度，二则是产生的数字比较乱便于隐蔽
            char[] seq = "371482506".ToCharArray();        // 这里定义 0-8 九个数字用于打乱得到的code
            var code = "";
            for (int i = 0; i < 9; i++)
            {
                int index = int.Parse(seq[i].ToString());
                code += tempcode[index];
            }
            return pre + "_" + code;

        }
    }
}